package com.ejuornal.service.impl;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.ejuornal.bean.Page;
import com.ejuornal.bean.Store;
import com.ejuornal.dao.impl.StoreDaoImpl;
import com.ejuornal.service.StoreService;

@Component("storeService")
public class StoreServiceImpl implements StoreService {
	private StoreDaoImpl storeDao;

	public StoreDaoImpl getStoreDao() {
		return storeDao;
	}

	@Resource(name = "storeDao")
	public void setStoreDao(StoreDaoImpl storeDao) {
		this.storeDao = storeDao;
	}

	public void add(Store store) {
		String sql = "INSERT INTO t_store value(?, ?, ?, ?, ?)";
//	    Date date = new Date();
//	    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//	    String date1 =sdf.format(date);
		storeDao.add(sql,
				new Object[] { null, store.getUserId(), store.getContentId(),
						store.getType(), new Date()});
	}

	public void delete(int... store) {
		String sql = "DELETE FROM t_store WHERE storeId = ?";
		storeDao.batchDelete(sql, store);
	}

	public Store findById(int storeId) {
		Store store = storeDao.findById(storeId);
		return store;
	}

	public Page<Store> findByUserId(int current_record, String url,
			 int userId) {
		return storeDao.find_2(current_record, url, new Object[]{userId});
		
	}

	@Override
	public int checkIsStore(int userId, int articalId) {
		return storeDao.checkIsStore(userId, articalId);
	}

//	public Page<Store> findByContentId(int current_record, String url,
//			String type, int contentId) {
//		String hsql = "where type=? and contentId = ?";
//		return storeDao.find(current_record, url, hsql, new Object[] { type,
//				contentId });
//	}

}
